<?php 

abstract class Ext_Shopping_Fetch_Parse_Abstract implements Ext_Shopping_Fetch_Parse_Interface
{
    protected $_url;
    protected $_html;
    
    protected $_datas = array(
        'host'   => null,
        'viewId' => null,
        'title'  => null,
        'photo'  => null,
    );

    protected $_messages = array();
    protected $_messager;
    const HOST_EMPTY     = 'shoppingHostEmpty';
    const VIEW_ID_EMPTY  = 'shoppingViewIdEmpty';
    const NAME_EMPTY     = 'shoppingNameEmpty';
    const PHOTO_EMPTY    = 'shoppingPhotoEmpty';
    const PRICE_EMPTY    = 'shoppingPriceEmpty';
    protected $_messageTemplates = array(
        self::HOST_EMPTY    => "Fetch shopping 'host' failed.",
        self::VIEW_ID_EMPTY => "Fetch shopping 'viewId' failed.",
        self::NAME_EMPTY   => "Fetch shopping 'name' failed.",
        self::PHOTO_EMPTY   => "Fetch shopping 'photo' failed.",
        self::PRICE_EMPTY   => "Fetch shopping 'price' failed.",
    );
    
    public function __construct($url, $html)
    {
        $this->_url  = $url;
        $this->_html = $html;
        
        $this->_messager = new Ext_Messager($this->_messageTemplates);
    }
    
    public function getMessages()
    {
        return $this->_messages;
    }
    
    public function addMessage($message)
    {
        $this->_messages[] = $message;
    }
    
    public function addMessages($messages)
    {
        $this->_messages = array_merge($this->_messages, $messages);
    }

    public function getDatas()
    {
        return $this->_datas;
    }
    
    public function isValid()
    {
        $result = true;
        if(!$this->_datas['host']){
            $this->addMessage($this->_messager->addMessage(self::HOST_EMPTY));
            $result = false;
        }
        if(!$this->_datas['viewId']){
            $this->addMessage($this->_messager->addMessage(self::VIEW_ID_EMPTY));
            $result = false;
        }
        if(!$this->_datas['name']){
            $this->addMessage($this->_messager->addMessage(self::NAME_EMPTY));
            $result = false;
        }
        if(!$this->_datas['photo']){
            $this->addMessage($this->_messager->addMessage(self::PHOTO_EMPTY));
            $result = false;
        }
        if(!$this->_datas['price']){
            $this->addMessage($this->_messager->addMessage(self::PRICE_EMPTY));
            $result = false;
        }
        
        return $result;
    }
}